/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.qp.smsmarketing.view;

import com.qp.smsmarketing.controller.ControleLembrete;
import com.qp.smsmarketing.controller.NovoLembreteController;
import com.qp.smsmarketing.dao.LembreteDAO;
import com.qp.smsmarketing.entity.Lembrete;
import java.util.Date;
import java.util.List;
import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JOptionPane;

/**
 *
 * @author joasramos
 */
public class ViewInformacaoLembrete extends javax.swing.JDialog {

    /**
     * Creates new form ViewInformacaoLembrete
     */
    private Date dataSelecionada;
    private List<Lembrete> listaLembretes;
    private LembreteDAO dao;
    private NovoLembreteController controle;
    private Lembrete lembrete;

    public ViewInformacaoLembrete(java.awt.Frame parent, Date data, boolean modal) {
        super(parent, modal);
        this.dataSelecionada = data;
        initComponents();
        carregaCombo(dao);
        setLocationRelativeTo(null);
        setVisible(modal);

    }

    /**
     *
     * @param parent
     * @param data
     * @param listaLembretes
     * @param modal
     */
    public ViewInformacaoLembrete(java.awt.Frame parent, Date data, List<Lembrete> listaLembretes, LembreteDAO daolembrete, boolean modal) {
        super(parent, modal);
        this.dataSelecionada = data;
        this.dao = daolembrete;
//        this.listaLembretes = listaLembretes;
        initComponents();
        carregaCombo(dao);
        setLocationRelativeTo(null);
        setVisible(modal);
    }

    public JLabel getLbdatacompleta() {
        return lbdatacompleta;
    }

    public void setLbdatacompleta(JLabel lbdatacompleta) {
        this.lbdatacompleta = lbdatacompleta;
    }

    public JComboBox getJcbLembreteDia() {
        return jcbLembreteDia;
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jTextField1 = new javax.swing.JTextField();
        jLabel2 = new javax.swing.JLabel();
        jPanel2 = new javax.swing.JPanel();
        jPanel1 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        taDescricao = new javax.swing.JTextArea();
        jLabel4 = new javax.swing.JLabel();
        jScrollPane2 = new javax.swing.JScrollPane();
        taInformacaoAdicionais = new javax.swing.JTextArea();
        jcbLembreteDia = new javax.swing.JComboBox();
        jPanel3 = new javax.swing.JPanel();
        lbdatacompleta = new javax.swing.JLabel();
        jPanel4 = new javax.swing.JPanel();
        jButton1 = new javax.swing.JButton();
        jButton2 = new javax.swing.JButton();
        jButton3 = new javax.swing.JButton();
        jButton4 = new javax.swing.JButton();

        jTextField1.setText("jTextField1");

        jLabel2.setText("jLabel2");

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 100, Short.MAX_VALUE)
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 100, Short.MAX_VALUE)
        );

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
        setResizable(false);
        setType(java.awt.Window.Type.UTILITY);

        org.jdesktop.swingx.border.DropShadowBorder dropShadowBorder1 = new org.jdesktop.swingx.border.DropShadowBorder();
        dropShadowBorder1.setShowLeftShadow(true);
        jPanel1.setBorder(dropShadowBorder1);

        jLabel1.setText("Lembretes do Dia:");

        jLabel3.setText("Descrição");

        taDescricao.setColumns(20);
        taDescricao.setRows(5);
        jScrollPane1.setViewportView(taDescricao);

        jLabel4.setText("Informaçoes Adicionais");

        taInformacaoAdicionais.setColumns(20);
        taInformacaoAdicionais.setRows(5);
        jScrollPane2.setViewportView(taInformacaoAdicionais);

        jcbLembreteDia.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jcbLembreteDiaActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane2)
                    .addComponent(jScrollPane1)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel4)
                            .addComponent(jLabel3)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addComponent(jLabel1)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jcbLembreteDia, javax.swing.GroupLayout.PREFERRED_SIZE, 240, javax.swing.GroupLayout.PREFERRED_SIZE)))
                        .addGap(0, 0, Short.MAX_VALUE)))
                .addContainerGap())
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(jcbLembreteDia, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addComponent(jLabel3)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 65, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jLabel4)
                .addGap(1, 1, 1)
                .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 65, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(21, 21, 21))
        );

        org.jdesktop.swingx.border.DropShadowBorder dropShadowBorder2 = new org.jdesktop.swingx.border.DropShadowBorder();
        dropShadowBorder2.setShowLeftShadow(true);
        jPanel3.setBorder(dropShadowBorder2);

        lbdatacompleta.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        lbdatacompleta.setIcon(new javax.swing.ImageIcon(getClass().getResource("/com/qp/smsmarketing/resource/icon/16X16/notepad.png"))); // NOI18N
        lbdatacompleta.setText("Lembrete(s) do Dia");

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addGap(129, 129, 129)
                .addComponent(lbdatacompleta, javax.swing.GroupLayout.PREFERRED_SIZE, 154, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel3Layout.createSequentialGroup()
                .addContainerGap(18, Short.MAX_VALUE)
                .addComponent(lbdatacompleta)
                .addContainerGap())
        );

        org.jdesktop.swingx.border.DropShadowBorder dropShadowBorder3 = new org.jdesktop.swingx.border.DropShadowBorder();
        dropShadowBorder3.setShowLeftShadow(true);
        jPanel4.setBorder(dropShadowBorder3);

        jButton1.setForeground(new java.awt.Color(153, 153, 153));
        jButton1.setText("Excluir Lembrete");
        jButton1.setToolTipText("");
        jButton1.setAlignmentY(0.0F);
        org.jdesktop.swingx.border.DropShadowBorder dropShadowBorder4 = new org.jdesktop.swingx.border.DropShadowBorder();
        dropShadowBorder4.setShadowOpacity(1.0F);
        dropShadowBorder4.setShowRightShadow(false);
        dropShadowBorder4.setShowTopShadow(true);
        jButton1.setBorder(dropShadowBorder4);
        jButton1.setOpaque(false);
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        jButton2.setForeground(new java.awt.Color(153, 153, 153));
        jButton2.setText("Atualizar Lembrete");
        jButton2.setAlignmentY(0.0F);
        org.jdesktop.swingx.border.DropShadowBorder dropShadowBorder5 = new org.jdesktop.swingx.border.DropShadowBorder();
        dropShadowBorder5.setShadowOpacity(1.0F);
        dropShadowBorder5.setShowRightShadow(false);
        dropShadowBorder5.setShowTopShadow(true);
        jButton2.setBorder(dropShadowBorder5);
        jButton2.setOpaque(false);
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });

        jButton3.setForeground(new java.awt.Color(153, 153, 153));
        jButton3.setText("Sair");
        jButton3.setAlignmentY(0.0F);
        org.jdesktop.swingx.border.DropShadowBorder dropShadowBorder6 = new org.jdesktop.swingx.border.DropShadowBorder();
        dropShadowBorder6.setShadowOpacity(1.0F);
        dropShadowBorder6.setShowRightShadow(false);
        dropShadowBorder6.setShowTopShadow(true);
        jButton3.setBorder(dropShadowBorder6);
        jButton3.setOpaque(false);
        jButton3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton3ActionPerformed(evt);
            }
        });

        jButton4.setForeground(new java.awt.Color(153, 153, 153));
        jButton4.setText("Novo Lembrete");
        jButton4.setToolTipText("");
        jButton4.setAlignmentY(0.0F);
        org.jdesktop.swingx.border.DropShadowBorder dropShadowBorder7 = new org.jdesktop.swingx.border.DropShadowBorder();
        dropShadowBorder7.setShadowOpacity(1.0F);
        dropShadowBorder7.setShowRightShadow(false);
        dropShadowBorder7.setShowTopShadow(true);
        jButton4.setBorder(dropShadowBorder7);
        jButton4.setOpaque(false);
        jButton4.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton4ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(jPanel4);
        jPanel4.setLayout(jPanel4Layout);
        jPanel4Layout.setHorizontalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addGap(60, 60, 60)
                .addComponent(jButton4)
                .addGap(18, 18, 18)
                .addComponent(jButton2)
                .addGap(18, 18, 18)
                .addComponent(jButton1)
                .addGap(16, 16, 16)
                .addComponent(jButton3)
                .addContainerGap(67, Short.MAX_VALUE))
        );
        jPanel4Layout.setVerticalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                .addComponent(jButton1)
                .addComponent(jButton2)
                .addComponent(jButton3)
                .addComponent(jButton4))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addComponent(jPanel4, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, 239, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton4ActionPerformed

        new ViewNovoLembrete(null, dataSelecionada, true);
        carregaCombo(dao);
//        this.dispose();
    }//GEN-LAST:event_jButton4ActionPerformed

    private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed
        this.dispose();
        // TODO add your handling code here:
    }//GEN-LAST:event_jButton3ActionPerformed

    private void jcbLembreteDiaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jcbLembreteDiaActionPerformed
        carregaDescricao(jcbLembreteDia.getSelectedItem());
        carregaInformacao(jcbLembreteDia.getSelectedItem());
    }//GEN-LAST:event_jcbLembreteDiaActionPerformed

    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
        controle = new NovoLembreteController();
        lembrete = new Lembrete();
        lembrete.setTitulo(jcbLembreteDia.getSelectedItem().toString());
        lembrete.setInformacao(taInformacaoAdicionais.getText());
        lembrete.setDescricao(taDescricao.getText());
        lembrete.setData(dataSelecionada); 
        if (controle.atualizar(lembrete)) {
            JOptionPane.showMessageDialog(this, "Lembrete atualizado com sucesso!");
        } else {
            JOptionPane.showMessageDialog(this, "Não foi possivel atualizar lembrete!");
        }

    }//GEN-LAST:event_jButton2ActionPerformed

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        controle = new NovoLembreteController();
        lembrete = new Lembrete();
        lembrete.setData(dataSelecionada);
        lembrete.setDescricao(taDescricao.getText());
        lembrete.setInformacao(taInformacaoAdicionais.getText());
        lembrete.setTitulo(jcbLembreteDia.getSelectedItem().toString());
        if (controle.excluir(lembrete)) {
            JOptionPane.showMessageDialog(this, "Excluido com sucesso!");
            carregaCombo(dao);
        } else {
            JOptionPane.showMessageDialog(this, "Não foi possivel excluir lembrete");
        }
//        carregaCombo(dao);
    }//GEN-LAST:event_jButton1ActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /*
         * Set the Nimbus look and feel
         */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /*
         * If Nimbus (introduced in Java SE 6) is not available, stay with the
         * default look and feel. For details see
         * http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(ViewInformacaoLembrete.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(ViewInformacaoLembrete.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(ViewInformacaoLembrete.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(ViewInformacaoLembrete.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /*
         * Create and display the dialog
         */
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                //Nada deve ser feito aqui;
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JButton jButton3;
    private javax.swing.JButton jButton4;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JTextField jTextField1;
    private javax.swing.JComboBox jcbLembreteDia;
    private javax.swing.JLabel lbdatacompleta;
    private javax.swing.JTextArea taDescricao;
    private javax.swing.JTextArea taInformacaoAdicionais;
    // End of variables declaration//GEN-END:variables

    /**
     *
     */
    private void carregaCombo(LembreteDAO dao) {
        jcbLembreteDia.removeAllItems();
        listaLembretes = dao.getlistaLembretesporData(dataSelecionada);
        if (listaLembretes != null) {
            for (int i = 0; i < listaLembretes.size(); i++) {
                jcbLembreteDia.addItem(listaLembretes.get(i));
            }
        }
    }

    private void carregaDescricao(Object selectedItem) {
        taDescricao.setText("");
        taDescricao.append((String) dao.getDescricao(selectedItem));
    }

    private void carregaInformacao(Object selectItem) {
        taInformacaoAdicionais.setText("");
        taInformacaoAdicionais.append((String) dao.getInformacao(selectItem));
    }
}
